package com.example.yigoumall.mapper;

import com.example.yigoumall.entity.Order;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface OrderMapper {
    
    @Select("SELECT * FROM easybuy_order")
    List<Order> findAll();
    
    @Select("SELECT * FROM easybuy_order WHERE id = #{id}")
    Order findById(Integer id);
    
    @Select("SELECT * FROM easybuy_order WHERE userId = #{userId}")
    List<Order> findByUserId(Integer userId);
    
    @Insert("INSERT INTO easybuy_order(userId, loginName, userAddress, createTime, cost, serialNumber) " +
            "VALUES(#{userId}, #{loginName}, #{userAddress}, #{createTime}, #{cost}, #{serialNumber})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Order order);
    
    @Update("UPDATE easybuy_order SET userId=#{userId}, loginName=#{loginName}, userAddress=#{userAddress}, " +
            "createTime=#{createTime}, cost=#{cost}, serialNumber=#{serialNumber} WHERE id=#{id}")
    int update(Order order);
    
    @Delete("DELETE FROM easybuy_order WHERE id=#{id}")
    int deleteById(Integer id);
}